package org.example.spring_frist.Wbook;

import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RequestMapping("b1")
@RestController
public class b1 {

    //属性注入
    @Resource(name = "b3")
    bookServer bookServer;

    //构造方注入
    @Autowired
    public b1(bookServer bookServer) {
        this.bookServer = bookServer;
    }

    //setter 注入
    @Autowired
    public void setBookServer(bookServer bookServer) {
        this.bookServer = bookServer;
    }


    /**
     * 结论 状态码
     * 1开头的待办，err和success都不走
     * 2开走走到success
     * 3 4 5 走到 err
     */
    @RequestMapping("t5")
    public void t5(HttpServletRequest request, HttpServletResponse response) {
        response.setStatus(501);
    }
    @RequestMapping("t4")
    public void t4(HttpServletRequest request, HttpServletResponse response) {
        response.setStatus(401);
    }
    @RequestMapping("t3")
    public void t3(HttpServletRequest request, HttpServletResponse response) {
        response.setStatus(301);
    }
    @RequestMapping("t2")
    public void t2(HttpServletRequest request, HttpServletResponse response) {
        response.setStatus(201);
    }
    @RequestMapping("t1")
    public void t1(HttpServletRequest request, HttpServletResponse response) {
        response.setStatus(101);
    }

    public void hh() {
        System.out.println(bookServer.id);
    }

    @RequestMapping("/param1")
    public String param1(String param) {
        return param;
    }

    @RequestMapping("/p")
    public void p() {
        System.out.println("b1");
    }
}


